/**
 * 
 */
package com.runningfox.Process;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.runningfox.humor.AbstractProcess;
import com.runningfox.humor.Action;
import com.runningfox.humor.ProcessCallback;
import com.runningfox.logic.Cache;
import com.runningfox.logic.Logic;
import com.runningfox.model.Joke;
import com.runningfox.model.ResultSet;

/**
 * @author lhy
 * 
 */
public class RefreshJokeProcess extends AbstractProcess implements
		ProcessCallback {
	Joke node;

	public RefreshJokeProcess(Handler handler, Joke node) {
		super(handler);
		// TODO Auto-generated constructor stub
		this.node = node;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.runningfox.Humor.AbstractProcess#runImpl()
	 */
	@Override
	protected void runImpl() {
		// TODO Auto-generated method stub
		this.handler.sendEmptyMessage(Action.CAHCEREFRESH);
		Logic.reqeustDetail(this, node);
	}

	@Override
	public void onFailed(ResultSet res) {
		// TODO Auto-generated method stub
		this.handler.sendEmptyMessage(Action.LOADJOKEFAIL);
	}


	@Override
	public void onSucess(ResultSet res) {
		// TODO Auto-generated method stub
		Message msg = new Message();
		Bundle data = new Bundle();
		msg.what = Action.LOADJOKE;
		String html = res.html;
		node.html = html;
		node.read = 1;
		data.putParcelable("node", node);
		msg.setData(data);
		handler.sendMessage(msg);
		Logic.saveJokeDetail(node);
	}

	@Override
	public void onHttp200() {
		// TODO Auto-generated method stub
		handler.sendEmptyMessage(Action.HTTP200);		
	}

	@Override
	public void onHttp404() {
		// TODO Auto-generated method stub
		handler.sendEmptyMessage(Action.HTTP404);
	}

	@Override
	public void onHttp500() {
		// TODO Auto-generated method stub
		handler.sendEmptyMessage(Action.HTTP500);
	}

	@Override
	public void onHttpFaild() {
		// TODO Auto-generated method stub
		handler.sendEmptyMessage(Action.HTTPFAIL);
	}

	@Override
	public void onParsing() {
		// TODO Auto-generated method stub
		handler.sendEmptyMessage(Action.PARSING);
	}

	@Override
	public void onParseFail() {
		// TODO Auto-generated method stub
		handler.sendEmptyMessage(Action.PARSEFAILED);
	}
}
